//index.js
//获取应用实例
const app = getApp()
 const Api = require("../../utils/api.js").API
 const Store = require("../../utils/store.js").store
 const codeZ = require("../../utils/util.js")
Page({
    data: {
       value:'',
       list:{},
       isShow:false,
       id:'',
    },
    onLoad(op) { 
        let that = this;
        if(op.item == ""){ 
            
          
        }else{
            var a = JSON.parse(op.item);
            that.setData({
                value:a['ckGroupName'],
                id:a['id']
            })
            Api.queryByGroupNoApi(a['ckGroupNo']).then(res=>{
                if(res.code == 0){
                     that.setData({
                         list:res.result
                     })
                    
                    
                    
                }
            })
        }
       
        
    },
    onShow: function() { 
       

    },
    clickCheng:function(e){
       
          let j = e.currentTarget.dataset.index;
          var comSta = `list.currGroup[${j}].groupState`;
         let a = this.data.list.currGroup[j].groupState;
          if(a == null){   
              this.setData({
                    [comSta]:'1'
              })   
          }else{
             this.setData({
                   [comSta]:null
             })
          }     
        
    },
    clickDe:function(e){ 
       
        let i = e.currentTarget.dataset.inde;
          let j = e.currentTarget.dataset.index;
          var comSta = `list.otherGroup[${i}].recipientInfo[${j}].groupState`;
         let a = this.data.list.otherGroup[i].recipientInfo[j].groupState;
          if(a == null){   
              this.setData({
                    [comSta]:'1'
              })   
          }else{
             this.setData({
                   [comSta]:null
             })
          }     
          console.log(this.data.list);
        // wx.navigateTo({
        //     url: '../shouDaoDetail/index',
        // })
    },
    addSLR:function(){
        wx.navigateTo({
            url: '../adressEdit/index',
        })
    },
    onChangeValue:function(e){
        this.setData({
            value:e.detail
        })
    },
    saveGroup:function(){     
        if(this.data.value == ''){
         return wx.showToast({
        icon: 'none',
        title: '标签名称'
          })
        }
        var ids =[];
        var aaa = this.data.list.currGroup;
        if(aaa != null && aaa.length >0){
            aaa.forEach(item=>{
              
                if(item != null){
                  
                        if(item.groupState != null){
                            ids.push(item['id']);
                        }
                    
                }
              
            })
        }
       
        var  arr = this.data.list.otherGroup;
        if(arr.length > 0){
            
       
        arr.forEach(item=>{
            var ar = item.recipientInfo;
            if(ar != null){
                ar.forEach(ite=>{
                    if(ite.groupState == null){
                        ids.push(ite['id']);
                    }
                })
            }
          
        })
        }
        ids.unshift(this.data.id);
        let data = {
            
            	"ckGroupName": this.data.value,
            	"ids": ids
            
        }
       
        Api.updateBiaoQianApi(data).then(res=>{
            wx.navigateBack();
        })
    }
});
